package interview.huawei.tjt.training.huaweijishitiku;

import java.util.Scanner;

// 合唱队
public class HJ24 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while ( sc.hasNextInt() ) {
            int n = sc.nextInt();

            // 存储输入的int型数组，长度为首次输入的值n
            int[] arr = new int[n];
            // 左侧小于srr[i]的个数
            int[] arrL = new int[n];
            // 右侧小于srr[i]的个数
            int[] arrR = new int[n];

            for ( int i = 0; i < n; i ++ ) {
                arr[i] = sc.nextInt();
            }

            // 遍历数组并存储每一位的小于其的左侧的数的个数
            for ( int i = 0; i < arr.length; i ++ ) {
                arrL[i] = 0;
                for ( int j = 0; j < i; j ++ ) {
                    if ( arr[i] > arr[j] ) {
                        arrL[i] = Math.max( arrL[j] + 1, arrL[i] );
                    }
                }
            }

            // 遍历数组并存储每一位的小于其的右侧的数的个数
            for ( int i = n - 1; i >= 0; i -- ) {
                arrR[i] = 0;
                for ( int j = n - 1; j > i; j -- ) {
                    if ( arr[i] > arr[j] ) {
                        arrR[i] = Math.max( arrR[j] + 1, arrR[i] );
                    }
                }
            }

            int maxValue = 0;
            for ( int i = 0; i < n; i ++ ) {
                maxValue = Math.max( maxValue, arrL[i] + arrR[i] + 1 );
            }

            System.out.println( n - maxValue );

        }

    }

}
